import { getFactoryDetailOrderSpareList } from '@/api/merchant'
import { ref } from 'vue'
import { FactoryDetailPart } from './types'

// 获取商家详情之工单配件列表的加载
const loading = ref(false)

// 商家详情之配件列表
const list = ref<Array<FactoryDetailPart>>([])

// 列表总条数
const total = ref(0)

/**
 * 获取列表方法
 * @param {string} id 商家id
 * @param {Object} data 分页配置
 * @param {number} data.limit 一页显示多少条
 * @param {number} data.page 当面页码
 */
const getList = async (id: string, data: { limit: number; page: number }) => {
  loading.value = true
  const res = await getFactoryDetailOrderSpareList(id, data)
  list.value = res.data.data.rows
  total.value = Number(res.data.data.total)
  loading.value = false
}

export default {
  total,
  list,
  loading,
  getList,
}
